<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<s:url value="/images" var="imgPath"/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/formValidator.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidatorRegex.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" src="/js/jquery.timePicker.js"></script>
<link rel="stylesheet" type="text/css" href="/css/timePicker.css"/>
		
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: null, showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate:new Date(), showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
		
		$("#startTime").timePicker({step:60, startTime:"00:00", endTime:"23:00"});
		$("#endTime").timePicker({step:60, startTime:"00:59", endTime:"23:59"});
		
		$.formValidator.initConfig({formid:"formObj",onerror:function(msg){alert(msg)},onsuccess:function(){return true;}});

		//栏位资料验证
		$("#startDate").formValidator().inputValidator({
			min:10,
			max:10,
			onerror:"起始时间不能为空值,且格式为yyyy-MM-dd" }).compareValidator({
			desid:"endDate",
			operateor:"<",
			onerror:"结束时间必须晚于起始"});
		$("#endDate").formValidator().inputValidator({	
			min:10,
			max:10,
			onerror:"结束时间不能为空值,且格式为yyyy-MM-dd" });
});	
</script>
<div style="color:red">
<s:actionerror/>
<s:actionmessage/>
<s:fielderror />
</div>
<s:form action="updateCouponItem.do" method="post" id="formObj" enctype="multipart/form-data">
<h1>Coupon Item维护</h1>
<s:hidden name="couponItemCode"/>
<s:hidden name="from"/>
<table class="tb-data" width="100%">
		<tr>
          <th colspan="2">
                                优惠码资料
          </th>
        </tr>
		<tr>
			<th>
				优惠码
			</th>
			<td>
				${couponItem.code}
				(
                <s:if test="%{couponItem.memberId == null && couponItem.orderId == null}">
					未啟用
                </s:if>
                <s:elseif test="%{couponItem.memberId != null && couponItem.orderId == null}">
                	未使用
                </s:elseif>
                <s:elseif test="%{couponItem.memberId != null && couponItem.orderId != null}">
					已使用
                </s:elseif>
				)
			</td>
		</tr>
		<tr>
			<th>
				会员代码
			</th>
			<td>
				<s:url id="viewMemberUrl" value="/member/view.do">
					<s:param name="memberId" value="%{couponItem.memberId}"></s:param>
				</s:url>
				<s:a href="%{viewMemberUrl}">
					${couponItem.memberId}
				</s:a>
			</td>
		</tr>
		<tr>
			<th>
				订单编号
			</th>
			<td>
				<s:url id="viewOrderUrl" value="/order/view.do">
					<s:param name="memberId" value="%{couponItem.orderId}"></s:param>
				</s:url>
				<s:a href="%{viewOrderUrl}" target="_blank">
					${couponItem.orderId}
				</s:a>
			</td>
		</tr>
		<tr>
			<th>
				充值日期
			</th>
			<td>
				<fmt:formatDate pattern="yyyy-MM-dd HH:mm" value="${couponItem.regDate}" />
			</td>
		</tr>
		<tr>
			<th>
				使用日期
			</th>
			<td>
				<fmt:formatDate pattern="yyyy-MM-dd HH:mm" value="${couponItem.useDate}" />
			</td>
		</tr>
		<tr>
			<th colspan="2" >礼券基本资料</th>
		</tr>
        <tr>
            <th>名称</th>
            <td>
              ${coupon.name}
            </td>
        </tr>
		<tr>
			<th>叙述</th>
			<td>
				${coupon.description}
			</td>
		</tr>
		<tr>
			<th>适用范围</th>
			<td>
				${applyRangTypeMenu.options[coupon.applyRangeType.code].name}
			</td>
		</tr>
		<tr>
			<th>范围设定
			</th>
			<td>
				${applyRangeTypeExtensionDisplay}
			</td>
		</tr>
		<tr>
		<th>激活日期</th>
		<td><fmt-rt:formatDate value="${couponItem.regDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
	</tr>
	<tr>
		<th>* 期间 起</th>
		<td>
			<s:textfield name="startDate" id="startDate" ></s:textfield>
			<s:textfield name="startTime" id="startTime" size="5" maxLength="5" ></s:textfield>
		</td>
	</tr>
	<tr>
		<th>* 期间 迄</th>
		<td>
			<s:textfield name="endDate" id="endDate" ></s:textfield>
			<s:textfield name="endTime" id="endTime" size="5" maxLength="5" ></s:textfield>
		</td>
	</tr>
		<tr>
			<th>礼券面额</th>
			<td>
				¥&nbsp;${coupon.faceValue}
			</td>
		</tr>
		<tr>
			<th>最低商品价格</th>
			<td>
				¥&nbsp;${coupon.minimumProductPrice}
			</td>
		</tr>
        <s:if test="%{coupon.status == @com.yaodian100.ec.coupon.entity.Coupon$Status@INACTIVE}">
    		<tr>
    			<th>状态</th>
    			<td>
    				<strong>
	    				${statusMenu.options[coupon.status.code].name}
    				</strong>
    			</td>
    		</tr>
        </s:if>
		<tr>
			<th>数量</th>
			<td>
				${coupon.amount}
			</td>
		</tr>
		<tr>
			<th>单一帐号限用一次</th>
			<td>
				<s:if test="%{coupon.isOnce}">
					是
				</s:if>
				<s:else>
					否
				</s:else>
				<s:hidden name="coupon.isOnce"/>
			</td>
		</tr>
</table>
<div class="f-link">
      <input type="submit" value="储存修改">
      <s:if test="%{from eq 'fc'}">
		<input type="button" onClick="window.location.href='${midContextPath}/coupon/view.do?couponUuid=${coupon.uuid}';" value="取消">
	  </s:if>
	  <s:else>
	    <input type="button" onClick="window.location.href='${midContextPath}/coupon/queryCouponByCouponItemCode.do?couponItemCode=${couponItem.code}';" value="取消">
	  </s:else>
</div>
</s:form>
